import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class Connector
{
    private String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	private Statement s;
    void init(String address, String user, String password) throws SQLException
    {
        try
        {
            Class.forName(driver).newInstance();
            Connection conn = null;
            Properties props = new Properties();
            props.put("user", user);
            props.put("password", password);
			conn = DriverManager.getConnection(
				"jdbc:microsoft:sqlserver://" + address, props);
            conn.setAutoCommit(false);
            s = conn.createStatement();
        }
        catch (Throwable e)
        {
            System.out.println("exception thrown:");
            if (e instanceof SQLException)
                printSQLError((SQLException) e);
            else
                e.printStackTrace();
        }
    }
	void getData()  throws SQLException 
	{
		try
		{
			ResultSet rs = s.executeQuery(
        		"select IDUsl, UslName from hs.dbo.dtTypesUsl");
				while (rs.next())
				{
					System.out.println(Integer.toString(rs.getInt("IDUsl")) +
					' ' + rs.getString("UslName"));
				}
				rs.close();
		}
        catch (Throwable e)
        {
            System.out.println("exception thrown:");
            if (e instanceof SQLException)
                printSQLError((SQLException) e);
            else
                e.printStackTrace();
        }
	}
    static void printSQLError(SQLException e)
    {
        while (e != null)
        {
            System.out.println(e.toString());
            e = e.getNextException();
        }
    }
}

